package com.yxt.net.websocket.handler;

import com.yxt.net.websocket.messages.MessageBody;
import org.springframework.web.socket.PongMessage;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.AbstractWebSocketHandler;

/**
 * <p>
 * WEB Socket 业务基类
 * </p>
 *
 * @author zhangxiaolin
 * @since 2022/2/10$ 10:13$
 */
public abstract class WebSocketService extends AbstractWebSocketHandler {
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        service(session,message);
    }

    /**
     * <p>
     * Sockert 业务处理转换类
     * </p>
     *
     * @author zhangxiaolin
     * @since 2022/2/10 10:23
     */
    private void service(WebSocketSession session, TextMessage message){
        MessageBody messageBody=new MessageBody();
        messageBody.setMessage(message.getPayload());
        doService(messageBody);
    }
    /**
     * <p>
     * 业务处理类
     * </p>
     *
     * @author zhangxiaolin
     * @since 2022/2/10 10:26
     */
    public abstract void doService(MessageBody messageBody);
}
